package ru.cod.rs;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.SurfaceHolder;

public class MainThread extends Thread {

	private Context context;
	private MainView view;

	private SurfaceHolder holder;
	private boolean ready = false;

	public void p() {
		ready = false;
	}

	public void c() {
		ready = true;
	}

	public MainThread(Context c, MainView v) {
		context = c;
		view = v;
		holder = view.getHolder();
	}

	@Override
	public void run() {
		while (ready) {
			Canvas canvas = null;
			try {
				synchronized (holder) {
					canvas = holder.lockCanvas();
					draw(canvas);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	private void draw(Canvas c) {
		c.drawColor(Color.BLUE);
	}
}
